package codetop.microsoft.T19;

import util.ListNode;

/**
 * @Author: 18362
 * @Create: 2022-08-16 13:57:23 星期二
 */
class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0, head), p = dummy, q = head;
        for (int i=0; i<n; ++i)
            q = q.next;
        while (q != null) {
            q = q.next;
            p = p.next;
        }
        p.next = p.next.next;
        return dummy.next;
    }
}